<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="第二十一章Servlet和HTTP请求协议01 Servlet_快速入门  概念：运行在服务器端的小程序。   Servlet就是一个接口，定义了Java类被浏览器访问到(tomcat识别)的规则。    将来我们自定义一个类，实现Servlet接口，复写方法。       快速入门：   创建JavaEE项目    定义一个类，实现Servlet接口   public class Servlet">
<meta property="og:type" content="article">
<meta property="og:title" content="Hexo">
<meta property="og:url" content="https://goofyer.gitee.io/notes-on-computer-expertise/2021/12/20/Java/%E7%AC%AC%E4%BA%8C%E5%8D%81%E4%B8%80%E7%AB%A0Servlet%E5%92%8CHTTP%E8%AF%B7%E6%B1%82%E5%8D%8F%E8%AE%AE/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="第二十一章Servlet和HTTP请求协议01 Servlet_快速入门  概念：运行在服务器端的小程序。   Servlet就是一个接口，定义了Java类被浏览器访问到(tomcat识别)的规则。    将来我们自定义一个类，实现Servlet接口，复写方法。       快速入门：   创建JavaEE项目    定义一个类，实现Servlet接口   public class Servlet">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2021-12-19T17:35:49.452Z">
<meta property="article:modified_time" content="2021-12-19T17:35:50.038Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/notes-on-computer-expertise/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/notes-on-computer-expertise/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/notes-on-computer-expertise/css/style.css">

  
    
<link rel="stylesheet" href="/notes-on-computer-expertise/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/notes-on-computer-expertise/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/notes-on-computer-expertise/">Home</a>
        
          <a class="main-nav-link" href="/notes-on-computer-expertise/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/notes-on-computer-expertise/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://goofyer.gitee.io/notes-on-computer-expertise"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-Java/第二十一章Servlet和HTTP请求协议" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/notes-on-computer-expertise/2021/12/20/Java/%E7%AC%AC%E4%BA%8C%E5%8D%81%E4%B8%80%E7%AB%A0Servlet%E5%92%8CHTTP%E8%AF%B7%E6%B1%82%E5%8D%8F%E8%AE%AE/" class="article-date">
  <time class="dt-published" datetime="2021-12-19T17:35:49.452Z" itemprop="datePublished">2021-12-20</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h2 id="第二十一章Servlet和HTTP请求协议"><a href="#第二十一章Servlet和HTTP请求协议" class="headerlink" title="第二十一章Servlet和HTTP请求协议"></a>第二十一章Servlet和HTTP请求协议</h2><h3 id="01-Servlet-快速入门"><a href="#01-Servlet-快速入门" class="headerlink" title="01 Servlet_快速入门"></a>01 Servlet_快速入门</h3><ul>
<li><ul>
<li><p>概念：运行在服务器端的小程序。</p>
<ul>
<li><ul>
<li>Servlet就是一个接口，定义了Java类被浏览器访问到(tomcat识别)的规则。</li>
</ul>
</li>
<li><ul>
<li>将来我们自定义一个类，实现Servlet接口，复写方法。</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>快速入门：</p>
<ul>
<li><ol>
<li>创建JavaEE项目</li>
</ol>
</li>
<li><ol>
<li><p>定义一个类，实现Servlet接口</p>
<ul>
<li><ul>
<li>public class ServletDemo1 implements Servlet {}</li>
</ul>
</li>
</ul>
</li>
</ol>
</li>
<li><ol>
<li>实现接口中的抽象方法</li>
</ol>
</li>
<li><ol>
<li><p>配置Servlet</p>
<ul>
<li><p>在web.xml中配置：</p>
<ul>
<li><!--配置Servlet -->
<servlet>
<servlet-name>demo1</servlet-name>
<servlet-class>cn.itcast.web.servlet.ServletDemo1</servlet-class>
</servlet>

</li>
</ul>
</li>
</ul>
<p><servlet-mapping><br>   <servlet-name>demo1&lt;/servlet-name&gt;<br>   <url-pattern>/demo1&lt;/url-pattern&gt;<br>&lt;/servlet-mapping&gt;</p>
</li>
</ol>
</li>
</ul>
</li>
</ul>
<ul>
<li><p>子主题 5</p>
<ul>
<li>子主题 1</li>
<li>子主题 2</li>
<li>子主题 3</li>
<li>子主题 4</li>
<li>子主题 5</li>
<li>子主题 6</li>
<li>子主题 7</li>
</ul>
</li>
<li><p>Servlet_执行原理</p>
<ul>
<li>当服务器接受到客户端浏览器的请求后，会解析请求URL路径，获取访问的Servlet的资源路径。</li>
<li>查找web.xml文件，是否有对应的<url-pattern>标签体内容。</li>
<li>如果有，则在找到对应的<servlet-class>全类名。</li>
<li>tomcat会将字节码文件加载进内存，并且创建其对象。</li>
<li>调用其方法。</li>
</ul>
</li>
</ul>
<h3 id="02-Servlet-生命周期"><a href="#02-Servlet-生命周期" class="headerlink" title="02 Servlet_生命周期"></a>02 Servlet_生命周期</h3><ul>
<li><p>Servlet中的生命周期方法：</p>
<ul>
<li>被创建：执行init方法，只执行一次。</li>
<li>提供服务：执行service方法，执行多次。</li>
<li>被销毁：执行destroy方法，只执行一次。</li>
</ul>
</li>
<li><p>代码</p>
<ul>
<li><p>/**</p>
<ul>
<li>Servlet的方法<br>*/<br>public class ServletDemo2 implements Servlet {</li>
</ul>
<p>/**</p>
<ul>
<li>初始化方法</li>
<li>在Servlet被创建时，执行。只会执行一次<br>*</li>
<li>@param servletConfig</li>
<li>@throws ServletException<br>*/<br>@Override<br>public void init(ServletConfig servletConfig) throws ServletException {<br>System.out.println(“init…”);<br>}</li>
</ul>
<p>/**</p>
<ul>
<li>获取ServletConfig对象</li>
<li>ServletConfig：Servlet的配置对象<br>*</li>
<li>@return<br>*/<br>@Override<br>public ServletConfig getServletConfig() {<br>return null;<br>}</li>
</ul>
<p>/**</p>
<ul>
<li>提供服务方法</li>
<li>每一次Servlet被访问时，执行。执行多次<br>*</li>
<li>@param servletRequest</li>
<li>@param servletResponse</li>
<li>@throws ServletException</li>
<li>@throws IOException<br>*/<br>@Override<br>public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {<br>System.out.println(“service…”);<br>}</li>
</ul>
<p>/**</p>
<ul>
<li>获取Servlet的一些信息，版本、作者等…<br>*</li>
<li>@return<br>*/<br>@Override<br>public String getServletInfo() {<br>return null;<br>}</li>
</ul>
<p>/**</p>
<ul>
<li>销毁方法</li>
<li>在服务器正常关闭时（Servlet销毁），执行，执行一次。<br>*/<br>@Override<br>public void destroy() {<br>System.out.println(“destroy…”);<br>}<br>}</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="Servlet-生命周期详解"><a href="#Servlet-生命周期详解" class="headerlink" title="Servlet_生命周期详解"></a>Servlet_生命周期详解</h3><ul>
<li><ol>
<li><p>被创建：执行init方法，只执行一次。</p>
<ul>
<li><ul>
<li><p>Servlet什么时候被创建？</p>
<ul>
<li><ul>
<li>默认情况下，第一次被访问时，Servlet被创建。</li>
</ul>
</li>
<li><ul>
<li><p>可以配置执行Servlet的创建时机。</p>
<ul>
<li><ul>
<li><p>在<servlet>标签下配置</p>
<ul>
<li><ol>
<li><p>第一次被访问时，创建</p>
<ul>
<li><ul>
<li><load-on-startup>的值为负数</li>
</ul>
</li>
</ul>
</li>
</ol>
</li>
<li><ol>
<li><p>在服务器启动时，创建</p>
<ul>
<li><ul>
<li><load-on-startup>的值为0或正整数</li>
</ul>
</li>
<li><ul>
<li>Servlet的init方法，只执行一次，说明一个Servlet在内存中只存在一个对象，Servlet是单例的。</li>
</ul>
</li>
<li><ul>
<li>多个用户同时访问时，可能存在线程安全问题。</li>
</ul>
</li>
<li><ul>
<li>解决：尽量不要在Servlet中定义成员变量。即使定义了成员变量，也不要修改其值（避免并发操作）。</li>
</ul>
</li>
</ul>
</li>
</ol>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ol>
</li>
<li><ol>
<li><p>提供服务：执行service方法，执行多次。</p>
<ul>
<li><ul>
<li>每次访问Servlet时，Service方法都会被调用一次。</li>
</ul>
</li>
</ul>
</li>
</ol>
</li>
<li><ol>
<li><p>被销毁：执行destroy方法，只执行一次。</p>
<ul>
<li><ul>
<li>Servlet被销毁时执行。服务器关闭时，Servlet被销毁。</li>
</ul>
</li>
<li><ul>
<li>只有服务器正常关闭时，才会执行destroy方法。</li>
</ul>
</li>
<li><ul>
<li>destroy方法在Servlet被销毁之前执行，一般用于释放资源。</li>
</ul>
</li>
</ul>
</li>
</ol>
</li>
<li><p>&lt;?xml version=”1.0” encoding=”UTF-8”?&gt;</p>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
       version="3.1">

  <!--配置Servlet -->
  <servlet>
      <servlet-name>demo1</servlet-name>
      <servlet-class>cn.itcast.web.servlet.ServletDemo1</servlet-class>
  </servlet>
  <servlet-mapping>
      <servlet-name>demo1</servlet-name>
      <url-pattern>/demo1</url-pattern>
  </servlet-mapping>

  <!--配置Servlet -->
  <servlet>
      <servlet-name>demo2</servlet-name>
      <servlet-class>cn.itcast.web.servlet.ServletDemo2</servlet-class>
      <!--指定Servlet的创建时机
          1.第一次被访问时，创建
              * <load-on-startup>的值为负数（默认值为-1）
          2.在服务器启动时，创建
              * <load-on-startup>的值为0或正整数
      -->
      <load-on-startup>-5</load-on-startup>
  </servlet>

<p>  <servlet-mapping></p>
<pre><code>  &lt;servlet-name&gt;demo2&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/demo2&lt;/url-pattern&gt;
</code></pre><p>  &lt;/servlet-mapping&gt;</p>
</li>
</ul>
<p>&lt;/web-app&gt;</p>
<h3 id="03-Servlet-3-0注解配置"><a href="#03-Servlet-3-0注解配置" class="headerlink" title="03 Servlet_3.0注解配置"></a>03 Servlet_3.0注解配置</h3><ul>
<li><ul>
<li><p>好处：</p>
<ul>
<li><ul>
<li>支持注解配置。可以不需要web.xml了。</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><ul>
<li><p>步骤：</p>
<ul>
<li><ol>
<li>创建JavaEE项目，选择Servlet的版本3.0以上，可以不创建web.xml</li>
</ol>
</li>
<li><ol>
<li>定义一个类，实现Servlet接口</li>
</ol>
</li>
<li><ol>
<li>复写方法</li>
</ol>
</li>
<li><ol>
<li>在类上使用@WebServlet注解，进行配置</li>
</ol>
</li>
<li><ul>
<li><p>@WebServlet(“资源路径”)</p>
<ul>
<li>public @interface WebServlet {}<br>按住“Ctrl键”，点击“WebServlet”：</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>@Target({ElementType.TYPE})<br>@Retention(RetentionPolicy.RUNTIME)<br>@Documented<br>public @interface WebServlet {<br>    String name() default “”; // 相当于<Servlet-name></p>
<pre><code>String[] value() default &#123;&#125;; // 代表urlPatterns()属性配置

String[] urlPatterns() default &#123;&#125;; // 相当于&lt;url-pattern&gt;

int loadOnStartup() default -1; // 相当于&lt;load-on-startup&gt;

WebInitParam[] initParams() default &#123;&#125;;

boolean asyncSupported() default false;

String smallIcon() default &quot;&quot;;

String largeIcon() default &quot;&quot;;

String description() default &quot;&quot;;

String displayName() default &quot;&quot;;
</code></pre><p>}<br>Servlet_3.0注解配置方式2</p>
<p>public class ServletDemo implements Servlet {}<br>package cn.itcast.web.servlet;</p>
<p>import javax.servlet.*;<br>import javax.servlet.annotation.WebServlet;<br>import java.io.IOException;</p>
<p>@WebServlet(“/demo2”)<br>public class ServletDemo implements Servlet {<br>    @Override<br>    public void init(ServletConfig servletConfig) throws ServletException {<br>    }</p>
<pre><code>@Override
public ServletConfig getServletConfig() &#123;
    return null;
&#125;

@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException &#123;
    System.out.println(&quot;Servlet3.0来了...&quot;);
&#125;

@Override
public String getServletInfo() &#123;
    return null;
&#125;

@Override
public void destroy() &#123;
&#125;
</code></pre><p>}</p>
<h3 id="04-IDEA与tomcat相关配置"><a href="#04-IDEA与tomcat相关配置" class="headerlink" title="04 IDEA与tomcat相关配置"></a>04 IDEA与tomcat相关配置</h3><ul>
<li><ol>
<li><p>IDEA会为每一个tomcat部署的项目单独建立一份配置文件。</p>
<ul>
<li><ul>
<li>查看控制台的log：Using CATALINA_BASE:   “C:\Users\fqy.IntelliJIdea2018.1\system\tomcat_itcast”</li>
</ul>
</li>
</ul>
</li>
</ol>
</li>
<li><ol>
<li><p>工作空间项目和tomcat部署的web项目</p>
<ul>
<li><ul>
<li>tomcat真正访问的是“tomcat部署的web项目”，”tomcat部署的web项目”对应着”工作空间项目”的web目录下的所有资源。</li>
</ul>
</li>
<li><ul>
<li>WEB-INF目录下的资源不能被浏览器直接访问。</li>
</ul>
</li>
</ul>
</li>
</ol>
</li>
<li><ol>
<li>断点调试：使用”小虫子”启动（dubug 启动）</li>
</ol>
</li>
</ul>
<h3 id="05-Servlet-体系结构与urlpartten配置"><a href="#05-Servlet-体系结构与urlpartten配置" class="headerlink" title="05 Servlet_体系结构与urlpartten配置"></a>05 Servlet_体系结构与urlpartten配置</h3><ul>
<li><ol>
<li>概念</li>
</ol>
</li>
<li><ol>
<li>步骤</li>
</ol>
</li>
<li><ol>
<li>执行原理</li>
</ol>
</li>
<li><ol>
<li>生命周期</li>
</ol>
</li>
<li><ol>
<li>Servlet3.0 注解配置</li>
</ol>
</li>
<li><ol>
<li><p>Servlet的体系结构    </p>
<ul>
<li>Servlet — 接口</li>
<li>GenericServlet（儿子）— 抽象类</li>
<li>HttpServlet（孙子）— 抽象类</li>
</ul>
</li>
</ol>
</li>
<li><ul>
<li>GenericServlet：将Servlet接口中其他的方法做了默认空实现，只将service()方法作为抽象。</li>
</ul>
</li>
<li><ul>
<li>将来定义Servlet类时，可以继承GenericServlet，实现service()方法即可。</li>
</ul>
</li>
<li><ul>
<li><p>HttpServlet：对http协议的一种封装，简化操作。</p>
<ul>
<li><ol>
<li>定义类继承HttpServlet</li>
</ol>
</li>
<li><ol>
<li>复写doGet/doPost方法</li>
</ol>
</li>
</ul>
</li>
</ul>
</li>
<li><p>package cn.itcast.web.servlet;</p>
</li>
</ul>
<p>import javax.jws.WebService;<br>import javax.servlet.*;<br>import javax.servlet.annotation.WebServlet;<br>import java.io.IOException;</p>
<p>@WebServlet(urlPatterns = “/demo1”) // 设置虚拟访问路径<br>public class ServletDemo1 implements Servlet{<br>    @Override<br>    public void init(ServletConfig servletConfig) throws ServletException {<br>    }</p>
<pre><code>@Override
public ServletConfig getServletConfig() &#123;
    return null;
&#125;

@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException &#123;
    System.out.println(&quot;demo1-service...&quot;);
&#125;

@Override
public String getServletInfo() &#123;
    return null;
&#125;

@Override
public void destroy() &#123;

&#125;
</code></pre><p>}<br>public class ServletDemo2 extends GenericServlet {}</p>
<ul>
<li>package cn.itcast.web.servlet;</li>
</ul>
<p>import javax.servlet.GenericServlet;<br>import javax.servlet.ServletException;<br>import javax.servlet.ServletRequest;<br>import javax.servlet.ServletResponse;<br>import javax.servlet.annotation.WebServlet;<br>import java.io.IOException;</p>
<p>@WebServlet(“/demo2”)<br>public class ServletDemo2 extends GenericServlet {<br>    //不需要复写Servlet其它方法，只需要复写service方法<br>    //空实现Servlet其它方法，只写方法生命、不写方法体<br>    @Override<br>    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {<br>        System.out.println(“demo2…”);<br>    }<br>}</p>
<ul>
<li>package cn.itcast.web.servlet;</li>
</ul>
<p>import javax.servlet.ServletException;<br>import javax.servlet.annotation.WebServlet;<br>import javax.servlet.http.HttpServlet;<br>import javax.servlet.http.HttpServletRequest;<br>import javax.servlet.http.HttpServletResponse;<br>import java.io.IOException;</p>
<p>@WebServlet(“/demo3”)<br>public class ServletDemo3 extends HttpServlet {<br>    @Override<br>    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {<br>//        super.doGet(req, resp);<br>        System.out.println(“doGet…”);<br>    }</p>
<pre><code>@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException &#123;
</code></pre><p>//        super.doPost(req, resp);<br>        System.out.println(“doPost…”);<br>    }<br>}</p>
<ul>
<li><p>Servlet_urlpartten配置</p>
<ul>
<li><ol>
<li>概念</li>
</ol>
</li>
<li><ol>
<li>步骤</li>
</ol>
</li>
<li><ol>
<li>执行原理</li>
</ol>
</li>
<li><ol>
<li>生命周期</li>
</ol>
</li>
<li><ol>
<li>Servlet3.0 注解配置</li>
</ol>
</li>
<li><ol>
<li>Servlet的体系结构    </li>
</ol>
</li>
<li><ol>
<li><p>Servlet相关配置</p>
<ul>
<li><ol>
<li><p>urlpartten：Servlet访问路径</p>
<ul>
<li><ol>
<li>一个Servlet可以定义多个访问路径 ： @WebServlet({“/d4”,”/dd4”,”/ddd4”})</li>
</ol>
</li>
</ul>
</li>
</ol>
</li>
<li><ol>
<li><p>路径定义规则：</p>
<ul>
<li><ol>
<li>/xxx：路径匹配</li>
</ol>
</li>
<li><ol>
<li>/xxx/xxx:多层路径，目录结构</li>
</ol>
</li>
<li><ol>
<li>*.do：扩展名匹配</li>
</ol>
</li>
</ul>
</li>
</ol>
</li>
</ul>
</li>
</ol>
</li>
</ul>
</li>
</ul>
<h3 id="06-HTTP请求协议"><a href="#06-HTTP请求协议" class="headerlink" title="06 HTTP请求协议"></a>06 HTTP请求协议</h3><ul>
<li><p>HTTP概念：</p>
<ul>
<li>Hyper Text Transfer Protocol 超文本传输协议</li>
</ul>
</li>
<li><ul>
<li>传输协议：定义了客户端和服务器端通信时，发送数据的格式。</li>
</ul>
</li>
<li><ul>
<li><p>特点：</p>
<ul>
<li><ol>
<li>基于TCP/IP的高级协议</li>
</ol>
</li>
<li><ol>
<li>默认端口号:80</li>
</ol>
</li>
<li><ol>
<li>基于请求/响应模型的:一次请求对应一次响应</li>
</ol>
</li>
<li><ol>
<li>无状态的：每次请求之间相互独立，不能交互数据</li>
</ol>
</li>
</ul>
</li>
</ul>
</li>
<li><ul>
<li><p>历史版本：</p>
<ul>
<li><ul>
<li>1.0：每一次请求响应都会建立新的连接</li>
</ul>
</li>
<li><ul>
<li>1.1：复用连接</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><p>HTTP请求消息数据格式</p>
<ul>
<li><ol>
<li><p>请求行</p>
<ul>
<li><p>请求方式 请求url 请求协议/版本</p>
<ul>
<li>GET /login.html    HTTP/1.1</li>
</ul>
</li>
<li><ul>
<li><p>请求方式：</p>
<ul>
<li><ul>
<li><p>HTTP协议有7种请求方式，常用的有2种。</p>
<ul>
<li><ul>
<li><p>GET：</p>
<ul>
<li><ol>
<li>请求参数在请求行中，在url后。</li>
</ol>
</li>
<li><ol>
<li>请求的url长度有限制</li>
</ol>
</li>
<li><ol>
<li>不太安全</li>
</ol>
</li>
</ul>
</li>
</ul>
</li>
<li><ul>
<li><p>POST：</p>
<ul>
<li><ol>
<li>请求参数在请求体中</li>
</ol>
</li>
<li><ol>
<li>请求的url长度没有限制</li>
</ol>
</li>
<li><ol>
<li>相对安全</li>
</ol>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ol>
</li>
<li><ol>
<li><p>请求头</p>
<ul>
<li>请求头名称: 请求头值</li>
</ul>
</li>
</ol>
</li>
<li><ol>
<li><p>请求空行</p>
<ul>
<li>空行</li>
</ul>
</li>
</ol>
</li>
<li><ol>
<li><p>请求体(正文)</p>
<ul>
<li><ul>
<li><p>字符串格式：</p>
<ul>
<li>POST /login.html    HTTP/1.1<br>Host: localhost<br>User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0<br>Accept: text/html,application/xhtml+xml,application/xml;q=0.9,<em>/</em>;q=0.8<br>Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2<br>Accept-Encoding: gzip, deflate<br>Referer: <a target="_blank" rel="noopener" href="http://localhost/login.html">http://localhost/login.html</a><br>Connection: keep-alive<br>Upgrade-Insecure-Requests: 1</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>username=zhangsan</p>
</li>
</ol>
</li>
</ul>
</li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://goofyer.gitee.io/notes-on-computer-expertise/2021/12/20/Java/%E7%AC%AC%E4%BA%8C%E5%8D%81%E4%B8%80%E7%AB%A0Servlet%E5%92%8CHTTP%E8%AF%B7%E6%B1%82%E5%8D%8F%E8%AE%AE/" data-id="cl403sxr5001ef8vu3k22g5or" data-title="" class="article-share-link">Share</a>
      
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/notes-on-computer-expertise/2021/12/20/Java/%E7%AC%AC%E4%BA%8C%E5%8D%81%E4%BA%8C%E7%AB%A0Request%E5%92%8CResponse/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          (no title)
        
      </div>
    </a>
  
  
    <a href="/notes-on-computer-expertise/2021/12/20/Java/%E7%AC%AC%E4%BA%8C%E5%8D%81%E7%AB%A0Tomcat/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title"></div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/C-%E5%B7%A5%E5%85%B7/">C#工具</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/C-%E5%B7%A5%E5%85%B7/">C++工具</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/Mysql/">Mysql</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/blender/">blender</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/linux/">linux</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/manim/">manim</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/spring/">spring</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/vba%E5%9F%BA%E7%A1%80%E6%93%8D%E4%BD%9C/">vba基础操作</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E5%88%9B%E9%80%A0%E6%A8%A1%E5%BC%8F/">创造模式</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/">操作系统</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/">操作系统基础知识</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%BC%80%E5%8F%91/">操作系统开发</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%95%B0%E5%AD%A6/">数学</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/">数据结构</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/">数据结构基础知识</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%A8%A1%E6%9D%BF/">模板</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/">深度学习</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E8%8B%B1%E8%AF%AD/">英语</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E8%99%9A%E5%B9%BB4/">虚幻4</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BB%84%E6%88%90%E5%8E%9F%E7%90%86/">计算机组成原理</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/">计算机网络</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/notes-on-computer-expertise/tags/C/" rel="tag">C++</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/notes-on-computer-expertise/tags/C/" style="font-size: 10px;">C++</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2022/05/">May 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2022/03/">March 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2022/02/">February 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2022/01/">January 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2021/12/">December 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/31/vue/%E5%89%8D%E7%AB%AF%E6%A1%86%E6%9E%B6%E9%AA%8C%E8%AF%81%E7%A0%81%E6%97%A0%E6%B3%95%E6%98%BE%E7%A4%BA/">(no title)</a>
          </li>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/26/%E6%95%B0%E6%8D%AE%E5%BA%93/navicat%E5%AE%89%E8%A3%85/">(no title)</a>
          </li>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/25/%E8%99%9A%E5%B9%BB4%E5%BC%95%E6%93%8E%E5%BC%80%E5%8F%91/%E8%99%9A%E5%B9%BB%E5%9B%9B%20mod%E5%88%B6%E4%BD%9C/">(no title)</a>
          </li>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/23/python/python%E6%89%B9%E9%87%8F%E7%94%9F%E6%88%90%E6%95%B0%E6%8D%AE/">(no title)</a>
          </li>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/23/vba%E5%9F%BA%E7%A1%80%E6%93%8D%E4%BD%9C%E7%AC%94%E8%AE%B0/EXCEL%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/">(no title)</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2022 John Doe<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/notes-on-computer-expertise/" class="mobile-nav-link">Home</a>
  
    <a href="/notes-on-computer-expertise/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/notes-on-computer-expertise/js/jquery-3.4.1.min.js"></script>



  
<script src="/notes-on-computer-expertise/fancybox/jquery.fancybox.min.js"></script>




<script src="/notes-on-computer-expertise/js/script.js"></script>





  </div>
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [ ["$","$"], ["\\(","\\)"] ],
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
            processEscapes: true
        }
    });
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax();
        for (var i = 0; i < all.length; ++i)
            all[i].SourceElement().parentNode.className += ' has-jax';
    });
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>
</body>
</html>